import { updateGrantAmount } from '@/api/network'
import { ref } from 'vue'

export default () => {
  const updateLoading = ref(false)
  const updateForm = ref<{
    grantAmount: string
    networkId: string
  }>({
    grantAmount: '',
    networkId: '',
  })

  const update = async () => {
    try {
      updateLoading.value = true
      const res = await updateGrantAmount(updateForm.value.grantAmount, updateForm.value.networkId)
      updateLoading.value = false
      return res.data
    } catch (error) {
      updateLoading.value = false
    }
  }

  const resetUpdateForm = () => {
    updateForm.value = {
      grantAmount: '',
      networkId: '',
    }
  }

  return {
    updateForm,
    updateLoading,
    update,
    resetUpdateForm,
  }
}
